public class Main {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] arr = new int[]{0,1,7,6,0,2,0,7};
        solution.duplicateZeros(arr);
    }
}
class Solution {
    public void duplicateZeros(int[] arr) {
        //寻找复写位置
        int cur = 0;
        int dest = -1;
        while(dest<arr.length-1) {
            if (arr[cur]==0) {
                dest+=2;
            } else{
                dest++;
            }
            if (dest<arr.length-1) {
                cur++;
            }
        }
        //特殊情况处理
        if(dest==arr.length) {
            cur--;
            arr[dest-1] = 0;
            dest-=2;
        }
        //正常进行复写
        while(cur>=0) {
            if (arr[cur]==0) {
                arr[dest]=0;
                arr[dest-1]=0;
                dest-=2;
            } else{
                arr[dest]=arr[cur];
                dest--;
            }
            cur--;
        }
    }
}